<?php
class Pago_mensual_model extends CI_Model {
    
    var $id = '';
    var $document_type_id = '';
    var $document_code = '';
    var $date = '';
    var $id_client = '';
    var $observations = '';
    private $_tabla = 'pago';
    private $_tabla2 = 'detalle_pago_mensual';
    
    public function addPurchase($data)
    {
        return $this->db->insert($this->_tabla, $data);
    }

    public function add_pago_mensual($data){
       return $this->db->insert($this->_tabla, $data);
    }
    
    public function add_detalle_pago_mensual($data){
       return $this->db->insert($this->_tabla2, $data);
    }
    
    public function search_contrato($document_code){

        $this->db->select();
        $this->db->where('document_code', ''.$document_code.'');
        $query = $this->db->get($this->_tabla);
        $rs = $query->result();
        
        return $rs;
        
    }
    
public function search_contrato2($id_client){

        $this->db->select();
        $this->db->where('id_cliente', ''.$id_client.'');
        $query = $this->db->get($this->_tabla);
        $rs = $query->result();
        
        return $rs;
        
    }
    
    public function update_contrato($id, $data)
        {
            
            $this->db->where('id_contrato', $id);
            $this->db->update($this->_tabla, $data);
            return true;
        }


    public function edit_amout($document_code,$amount){
         return $this->db->query("UPDATE sales SET amount='".$amount."' WHERE `document_code`='".$document_code."'");
    }
    
    public function edit_stock_warehouse_product($code_product,$code_warehouse,$caja,$paquete,$unidad){
        $this->db->query("UPDATE  `warehouses_product` SET  `Units`=".$unidad.", `packs`=".$paquete.", `boxes`=".$caja." WHERE  `id_warehouse` =".$code_warehouse." and id_product = '".$code_product."'");
    }
    
    public function comparaction_code($document_code){
        $query = $this->db->query("SELECT document_code FROM contrato where document_code = '".$document_code."'");
        $rs = $query->num_rows();
        return $rs;
    }
    
    public function select_almacen_productos($code_product, $code_almacen){
       $query = $this->db->query("SELECT * FROM  `warehouses_product` WHERE  `id_product` =  '".$code_product."' AND  `id_warehouse` = '".$code_almacen."'");
       $rs = $query->result();
       return $rs;
    }
    
    
    
    
    
}